﻿using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.Collections;
using System.Runtime.Serialization.Formatters;
using Gerenciamento;
using System.Diagnostics;

namespace Servidor
{
    class Program
    {
        [MTAThread]
        static void Main(string[] args)
        {
            configuraServidor();
            Console.WriteLine("Canal criado, aguardando requisições...");
            Console.ReadLine();
        }

        private static void configuraServidor()
        {
            BinaryClientFormatterSinkProvider clientProvider = null;

            BinaryServerFormatterSinkProvider serverProvider = 
                new BinaryServerFormatterSinkProvider();
            serverProvider.TypeFilterLevel =
                System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;

            IDictionary props = new Hashtable();
            props["port"] = 9000;
            props["typeFilterLevel"] = TypeFilterLevel.Full;

            TcpChannel chan = new TcpChannel(props, clientProvider, serverProvider);

            ChannelServices.RegisterChannel(chan);

            RemotingConfiguration.RegisterWellKnownServiceType(
                typeof(ServidorImpl),
                "Gerenciamento",
                WellKnownObjectMode.Singleton);
        }
    }
}
